package com.jpa;

import com.jpa.config.TenantContext;
import com.jpa.jooq.tables.daos.EuclidAssetsLedgerDao;
import com.jpa.jooq.tables.pojos.EuclidAssetsLedger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Autor: songfei
 * @Description:
 * @Date: Created in 22:38 2025/3/31
 **/
@Service
public class InsertService {
    @Autowired
    private EuclidAssetsLedgerDao euclidAssetsLedgerDao;

    @Transactional
    public void insert() {
        TenantContext.setCurrentTenant("ISIC");
        EuclidAssetsLedger ledger = new EuclidAssetsLedger();
        ledger.setCompanyCode("ISIC");
        euclidAssetsLedgerDao.insert(ledger);

        test1();
        test2();
        test3();


        System.out.println(1111111);
//        throw new RuntimeException("waaa");
    }


    public void test1(){
        TenantContext.setCurrentTenant("PA001");
        EuclidAssetsLedger ledger1 = new EuclidAssetsLedger();
        ledger1.setCompanyCode("PA001");
        euclidAssetsLedgerDao.insert(ledger1);
    }


    public void test2(){
        TenantContext.setCurrentTenant("PA002");
        EuclidAssetsLedger ledger2 = new EuclidAssetsLedger();
        ledger2.setCompanyCode("PA002");
        euclidAssetsLedgerDao.insert(ledger2);
    }


    public void test3(){
        TenantContext.setCurrentTenant("PA003");
        EuclidAssetsLedger ledger3 = new EuclidAssetsLedger();
        ledger3.setCompanyCode("PA003");
        euclidAssetsLedgerDao.insert(ledger3);
    }
}
